package com.mallcai.bigdata.ladon.service.export.impl.handler;

import com.mallcai.bigdata.ladon.dpl.entity.export.ExportTask;
import com.mallcai.bigdata.ladon.service.export.ITaskService;
import com.mallcai.bigdata.ladon.service.export.impl.ExportContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * described : 异步时,更新任务的状态,邮件或者OSS等方式均可用
 *
 * @author CaKeDou
 * @date 2019-09-26 21:52
 * Modify:
 */
@Component
@Order(700)
public class UpdateTaskHandler extends AbstractExportPostHandler {
    @Autowired
    private ITaskService taskService;

    @Override
    public void postInternal(ExportContext context) {
        if (!context.getExportStrategy().getAsyncInfo().isAsync()) {
            return;
        }
        Long taskId = context.getExportStrategy().getAsyncInfo().getTaskId();
        ExportTask exportTask = taskService.getStatus(taskId);
        exportTask.setTaskStatus(1);
        exportTask.setDownloadUrl(context.getDownloadUrl());
        taskService.updateTask(exportTask);
    }
}
